package com.example.es.controller;

import com.alibaba.fastjson.JSON;
import com.example.es.service.ConterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.List;
import java.util.Map;

/**
 * @description:
 * @author: 朱超
 * @createDate: 2021/9/16
 * @version: 1.0
 * @remark：备注
 */

@RestController
public class ConterController {
    @Autowired
    private ConterService conterService;

    @GetMapping("/index/{name}")
    public Boolean ss(@PathVariable("name") String name) throws IOException {
        return conterService.conter(name);
    }


    @GetMapping("/page/{name}/{pageNum}/{pageSize}")
    public List<Map<String, Object>> page(@PathVariable("name") String name,
                                          @PathVariable("pageNum") int pageNum,
                                          @PathVariable("pageSize") int pageSize) throws IOException {
       if (pageNum==0){
           pageNum=1;
       }
        List<Map<String, Object>> search = conterService.search(name, pageNum, pageSize);
        String toJSONString = JSON.toJSONString(search);
        return conterService.search(name, pageNum, pageSize);
    }

}
